<template>
  <scroll-view
    class="recommend_view"
    scroll-y
    @scrolltolower="handleToLower"
    v-if="album.length > 0"
  >
    <!-- 轮播图开始 -->
    <!-- 
          自动轮播属性  autoplay
          指示器属性    indicator-dots
          衔接轮播      circular

          swiper默认高度150px
          image默认高度240px
     -->
    <view class="album_swiper">
      <swiper>
        <swiper-item
          class="swiper_item"
          v-for="item in banner"
          :key="item.id"
          autoplay
          indicator-dots
          circular
        >
          <image :src="item.thumb"></image>
        </swiper-item>
      </swiper>
    </view>

    <!-- 列表开始 -->
    <view class="album_list">
      <navigator :url="`/pages/album/index?id=${item.id}`"  class="album_item" v-for="item in album" :key="item.id">
        <view class="album_img">
          <image :src="item.cover" mode="aspectFill"></image>
        </view>
        <view class="album_info">
          <view class="album_name">{{ item.name }}</view>
          <view class="album_desc">{{ item.desc }}</view>
          <view class="album_btn">
            <view class="album_attention">关注</view>
          </view>
        </view>
      </navigator>
    </view>
    <!-- 列表结束 -->
  </scroll-view>
</template>

<script>
export default {
  name: "UniHomeAlbum",

  data() {
    return {
      params: {
        limit: 30,
        order: "new",
        skip: 0,
      },
      banner: [],
      album: [],
      hasMore: true,
    };
  },

  mounted() {
    // 修改页面标题、
    uni.setNavigationBarTitle({ title: "专辑" });

    this.getList();

    
  },
  
    
  

  methods: {
    // 获取接口数据
    getList() {
      this.request({
        url: "http://service.picasso.adesk.com/v1/wallpaper/album",
        data: this.params,
      }).then((result) => {
        if(this.banner.length ===0){
          this.banner = result.res.banner;
        }
        if (result.res.album.length === 0) {
          this.hasMore = false;
          return;
        }
        console.log(result);
        this.album = [...this.album, ...result.res.album];
        
      });
    },
    // 滚动条触底事件
    handleToLower() {
      if (this.hasMore) {
        // 当滚动条到底事件触发时，修改请求参数 skip+=limit
        this.params.skip += this.params.limit;
        // 重新发送请求
        this.getList();
        // 请求成功后 进行数据的叠加
      } else {
        uni.showToast({
          title: "没有更多图片了",
          icon: "none",
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.recommend_view {
  // 屏幕的高度减去头部标签的高度
  height: calc(100vh - 36px);
}
.album_swiper {
  swiper {
    height: calc(750rpx / 2.3);
    image {
      height: 100%;
    }
  }
}
.album_list {
  padding: 10rpx;
  .album_item {
    padding: 10rpx 0;
    display: flex;
    border-bottom: 1rpx solid #ccc;
    .album_img {
      flex: 1;
      padding: 10rpx;
      image {
        width: 200rpx;
        height: 200rpx;
      }
    }

    .album_info {
      flex: 2;
      padding: 0 10rpx;
      overflow: hidden;
      .album_name {
        font-size: 30rpx;
        color: #000;
        padding: 10rpx 0;
      }

      .album_desc {
        padding: 10rpx 0;
        font-size: 24rpx;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
      }

      .album_btn {
        padding: 10rpx;
        display: flex;
        justify-content: flex-end;
        .album_attention {
          color: $color;
          border: 1rpx solid $color;
          padding: 10rpx;
        }
      }
    }
  }
}
</style>